package com.ques.dao;

import com.ques.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

/**
 * @author zq  2020-01-05
 */
@Repository
public class UserDao {
    @Autowired
    private MongoTemplate template ;

    public User selectUserByUsernameAndPassword(User user) {
        Query query = Query.query(Criteria.where("userMail").is( user.getUserMail() ).and("password").is(user.getPassword()));
        User one = template.findOne(query, User.class);
        if(one != null) {
            one.setPassword("");
            return  one ;
        }
        return  null;
    }
    public User selectUserInfoById(String userId) {
        User user = template.findById(userId, User.class);
        if(user != null) {
            //密码不暴露
            user.setPassword("");
            return  user ;
        }
        return   null ;
    }
}
